package com.xin.data.simbapesa.adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.viewbinding.ViewBinding;

import com.xin.data.simbapesa.R;
import com.xin.data.simbapesa.base.BaseBindingAdapter1;
import com.xin.data.simbapesa.databinding.SimbaApplyItem1Binding;
import com.xin.data.simbapesa.databinding.SimbaApplyItem2Binding;
import com.xin.data.simbapesa.databinding.SimbaApplyItem3Binding;
import com.xin.data.simbapesa.obj.SimbaDetailItemInfo;
import com.xin.data.simbapesa.utils.ResUtils;

import java.util.List;

public class ApplyAdapter extends BaseBindingAdapter1<SimbaDetailItemInfo, ViewBinding> {


    public ApplyAdapter(List<SimbaDetailItemInfo> dataList) {
        super(dataList);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void bindData(ViewBinding binding, SimbaDetailItemInfo item, int position) {
        if (binding instanceof SimbaApplyItem1Binding) {
            SimbaApplyItem1Binding binding1 = (SimbaApplyItem1Binding) binding;
            binding1.tvTitle.setText(item.getShowName());
            binding1.tvAmout.setText(item.getShowDetail());

        } else if (binding instanceof SimbaApplyItem2Binding) {
            SimbaApplyItem2Binding binding1 = (SimbaApplyItem2Binding) binding;
            binding1.tvAmout.setPaintFlags(binding1.tvAmout.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            if (!TextUtils.isEmpty(item.getDiscount())) {
                binding1.tvAmout2.setText(item.getDiscount());
            }
            binding1.tvAmout.setText(item.getOldDetail());

            if (!TextUtils.isEmpty(item.getShowName()) && !TextUtils.isEmpty(item.getShowDetail())) {
                binding1.tvTitle.setText(item.getShowName());
                binding1.tvAmout1.setText(item.getShowDetail());
            }

            if (position == 1) {
                binding1.tvRoot.setPadding(0, ResUtils.d(R.dimen.dp_10), 0, 0);
            } else {
                binding1.tvRoot.setPadding(0, 0, 0, 0);
            }


        } else if (binding instanceof SimbaApplyItem3Binding) {
            SimbaApplyItem3Binding binding1 = (SimbaApplyItem3Binding) binding;


            binding1.tvTitle.setTextColor(Color.parseColor("#666666"));

            binding1.tvTitle.setText(item.getShowName());
            binding1.tvAmout.setText(item.getShowDetail());

            if (position == 1) {
                binding1.tvRoot.setPadding(0, ResUtils.d(R.dimen.dp_10), 0, 0);
            } else {
                binding1.tvRoot.setPadding(0, 0, 0, 0);
            }

            if (item.isRePay()) {
                binding1.tvAmout.setTextColor(Color.parseColor("#000000"));
            } else {
                binding1.tvAmout.setTextColor(Color.parseColor("#4B5563"));
            }

        }
    }

    @Override
    protected int getItemType(SimbaDetailItemInfo item) {
        if (!TextUtils.isEmpty(item.getTitle()) && item.getTitle().equals("YES")) {
            return 1;
        } else if (!TextUtils.isEmpty(item.getOldDetail())) {
            return 2;
        }
        return 3;
    }

    @Override
    protected ViewBinding createBinding(LayoutInflater inflater, ViewGroup parent, int viewType) {
        if (viewType == 1) {
            return SimbaApplyItem1Binding.inflate(inflater, parent, false);
        } else if (viewType == 2) {
            return SimbaApplyItem2Binding.inflate(inflater, parent, false);
        }
        return SimbaApplyItem3Binding.inflate(inflater, parent, false);
    }


}